import argparse

import command


def windows_find():
    parser = argparse.ArgumentParser(description='文件查找')
    parser.add_argument('-d', '--directory', nargs='?', default='', help='目录')
    parser.add_argument('-p', '--pattern', nargs='?', default='', help='匹配表达式')
    deep = None
    args, unknown_args = parser.parse_known_args()
    if len(unknown_args) > 0:
        args.pattern = unknown_args[0]

    if len(unknown_args) > 1:
        args.directory = unknown_args[1]

    if len(unknown_args) > 2:
        args.deep = unknown_args[2]

    if deep is None:
        deep = '/r '

    while args.pattern == '':
        args.pattern = input("请输出查找关键字: ")

    if "*" not in args.pattern:
        args.pattern = "*" + args.pattern

    command_line = f"for {deep} {args.directory} %i in ({args.pattern}) do @echo %i"
    command.exe_command(command_line)


def linux_find():
    pass


def find():
    windows_find() if command.is_windows() else linux_find()


if __name__ == '__main__':
    find()
